package com.cat.dataStructure02;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/score-of-parentheses/description/
 * @create 2025/10/20 20:05
 * @since JDK17
 */

public class Solution32 {
    public int scoreOfParentheses(String s) {
        int n = s.length(), ans = 0, d = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '(') {
                d++;
            } else {
                d--;
                if (s.charAt(i - 1) == '(') {
                    ans += 1 << d;
                }
            }
        }
        return ans;
    }
}
